package com.tyrant.houtai;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.gson.Gson;
import com.sunshine.retrofit.HttpUtil;
import com.sunshine.retrofit.interfaces.ErrorFunListener;
import com.sunshine.retrofit.interfaces.Success;
import com.tyrant.houtai.bean.UserLocalResultBean;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UserLocalModifyActivity extends AppCompatActivity {

    @Bind(R.id.et_phone)
    EditText et_phone;
    @Bind(R.id.btn_query)
    Button btn_query;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_local_modify);
        ButterKnife.bind(this);
    }

    private void queryinfo() {
        new HttpUtil.Builder("users/findUserLocationByMobile")
                .Params("mobile", et_phone.getText().toString())
                .Tag(this)//需要取消请求的tag
                .Success(new Success() {
                    @Override
                    public void Success(String model) {
                        UserLocalResultBean contactUsBean = new Gson().fromJson(model, UserLocalResultBean.class);
                        if (contactUsBean.getFlag() == 1) {
                            Intent intent = new Intent(UserLocalModifyActivity.this, UserLocalModifyMapActivity.class);
                            intent.putExtra("data", model);
                            intent.putExtra("mobile", et_phone.getText().toString());
                            startActivity(intent);

                        }else{
                            Toast.makeText(UserLocalModifyActivity.this, "操作失败", Toast.LENGTH_SHORT).show();
                        }
                    }


                }).ErrorEventFunc(new ErrorFunListener() {
            @Override
            public void ErrorFun(Object... values) {
                String value = (String) values[1];
            }
        })
                .post();
    }

    @OnClick(R.id.btn_query)
    public void onClick() {
        queryinfo();
    }
}
